﻿using System;
using System.Collections.Generic;
using System.Text;

public class UserManager :Singleton<UserManager>
{
    List<UserToken> userList = new List<UserToken>();

    public List<UserToken> UserList { get => userList; set => userList = value; }

    //添加玩家
    public void AddUser(UserToken token)
    {
        userList.Add(token);
    }

    //删除玩家
    public void DelUser(UserToken token)
    {
        userList.Remove(token);
    }

    //判断玩家是否存在
    public bool HasUser(string username)
    {
        for (int i = 0; i < userList.Count; i++)
        {
            UserToken tk = userList[i];
            if (tk.user.username == username)
            {
                return true;
            }
        }
        return false;
    }

    //获取玩家
    public UserToken GetUser(string username)
    {
        for (int i = 0; i < userList.Count; i++)
        {
            if(userList[i].user.username==username)
            {
                return userList[i];
            }
        }
        return null;
    }

}
